package com.example.laboratory.ui.user.Laboratory;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.example.laboratory.R;
import com.example.laboratory.application.LApp;
import com.example.laboratory.bean.Laboratory;
import com.example.laboratory.common.Const;
import com.example.laboratory.inter.OnLabListItemClickListener;
import com.example.laboratory.manager.UserInfoManager;
import com.example.laboratory.ui.laboratory.LaboratoryActivity;
import com.example.laboratory.ui.adapter.BaseListAdapter;
import com.example.laboratory.ui.adapter.LaboratoryListAdapter;
import com.example.laboratory.ui.base.BaseAbListActivity;


import java.util.List;



public class LabListActivity extends BaseAbListActivity<LabPresenter, Laboratory.RowsBean> implements LabContract.ILabView, OnLabListItemClickListener {
    LApp lApp;

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        lApp= (LApp) getApplication();
    }

    @Override
    protected LabPresenter createPresenter() {
        return new LabPresenter();
    }

    @Override
    protected boolean initToolbar() {
        if (UserInfoManager.getUserInfo().getPermission().equals("1")){
            mToolbar.setTitle(R.string.mine_labs);
        }else if (UserInfoManager.getUserInfo().getPermission().equals("0")){
            mToolbar.setTitle("实验室");
        }

        return true;
    }
    @Override
    protected boolean isCanLoadMore() {
        return true;
    }
    @Override
    protected View initHeaderView() {
        return null;
    }
    @Override
    protected void loadDatas() {
        if (page == getFirstPage()){
            //刷新
            if (UserInfoManager.getUserInfo().getPermission().equals("1")){
                mPresenter.loadLaboratoryList(UserInfoManager.getUserInfo().getUid(),"");
            }else if (UserInfoManager.getUserInfo().getPermission().equals("0")){
                mPresenter.loadLaboratoryList("",UserInfoManager.getUserInfo().getDepartId());
            }

        }else {
            //加载更多
            //mPresenter.getMoreArticleList();
        }


    }

    @Override
    protected BaseListAdapter<Laboratory.RowsBean> getListAdapter() {
        return  new LaboratoryListAdapter(this);
    }



    @Override
    public void onRecordClick(int position, String id) {

    }




    @Override
    public void onItemClick(int position, Laboratory.RowsBean bean) {
        Intent intent = new Intent(this, LaboratoryActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable(Const.BUNDLE_KEY.OBJ, bean);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    @Override
    public void setData(List<Laboratory.RowsBean> data) {
        mListData.clear();
        mListData.addAll(data);

        lApp.setRowsBeans(mListData);
      //  Log.d("XXX",lApp.getRowsBeans().get(0).getLabel()+"ff");


    }

//    @Override
//    public List<Laboratory.RowsBean> getLabData() {
//        return mListData;
//    }
}
